import React from 'react';

import './style/';
import {WeaDialog, WeaFormItem, WeaSearchGroup, WeaRichText, WeaTools, WeaLocaleProvider} from "ecCom";
import {Icon, Button, message} from 'antd'
const getLabel = WeaLocaleProvider.getLabel;
class Copyright extends React.Component {

    state = {
        copyrightcon:"",
        visible:false
    }


    getDatas = () => {
        WeaTools.callApi('/api/portal/customcopyright/getCopyright','GET',{
            "id":this.props.id
        }).then((result) => {
            if(result.api_status==true&&result.isCz==true){
                this.setState({copyrightcon:result.setting.copyrightcon});
            }else if(result.api_status==true&&result.isCz==false){
            }
        })
    }

    saveSetting= () =>{
        WeaTools.callApi('/api/portal/customcopyright/saveCopyright','POST',{
            jsonStr: JSON.stringify({
                "copyrightcon":this.state.copyrightcon,
                "id":this.props.id,
            })
        }).then((result) =>{
            if(result.api_status==true){
                this.setState({visible:false});
                message.success(getLabel(83551,"保存成功！"),2);
            }else {
                message.error(getLabel(84544,"保存失败！"),2);
            }
        })
        this.setState({visible: false});
    }


    openDia = () => {
        this.setState({visible: true});
    }
    componentDidMount(){
        this.getDatas();
    }

    onCancel = () => {
        this.getDatas();
        this.setState({visible:false})
    }
    render() {
        const {copyrightcon,visible} = this.state;
        let display = "none";
        if(this.props.isSetting == true){
            display = "";
        }
        return (
            <div className="portal-com-copyright">
                <div className="div-diy-icon" onClick={this.openDia}   style={{"z-index":99,"display":display}}>
                    <Icon  onClick={this.openDia} className="portal-icon-copyright" type="setting" theme="filled"  />
                </div>
                <p dangerouslySetInnerHTML={{ __html: copyrightcon }} />

                <WeaDialog visible={visible} onCancel={this.onCancel} title={getLabel(387745,"文本设置")}>
                    <div style={{position:"relative",height:400}}>
                        <WeaRichText ref='test'
                                     value={copyrightcon}
                                     ckConfig={{
                                         toolbar: [{ name: 'test', items: [
                                                 'Source', '-', 'Styles', 'Format', 'Font', 'FontSize', 'Maximize','TextColor'] }],
                                     }}
                                     onChange={vlaue =>{ this.setState({copyrightcon: vlaue})}}
                        />
                        <div style={{position:"absolute",bottom:7,"margin-left": "67%"}}>
                            <Button onClick={this.saveSetting} type="primary">{getLabel(33703,"确认")}</Button>
                            <Button onClick={this.onCancel} style={{"margin-left":10}}>{getLabel(31129,"取消")}</Button>
                        </div>
                    </div>
                </WeaDialog>

            </div>
        );
    }
}

export default Copyright;